package cn.source.event.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.event.domain.DbEvent;
import cn.source.event.service.IDbEventService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * eventController
 * 
 * @author sourcebyte.vip
 * @date 2025-06-14
 */
@RestController
@RequestMapping("/event/event")
public class DbEventController extends BaseController
{
    @Autowired
    private IDbEventService dbEventService;

    /**
     * 查询event列表
     */
    @PreAuthorize("@ss.hasPermi('event:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbEvent dbEvent)
    {
        startPage();
        List<DbEvent> list = dbEventService.selectDbEventList(dbEvent);
        return getDataTable(list);
    }

    /**
     * 导出event列表
     */
    @PreAuthorize("@ss.hasPermi('event:event:export')")
    @Log(title = "event", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DbEvent dbEvent)
    {
        List<DbEvent> list = dbEventService.selectDbEventList(dbEvent);
        ExcelUtil<DbEvent> util = new ExcelUtil<DbEvent>(DbEvent.class);
        util.exportExcel(response, list, "event数据");
    }

    /**
     * 获取event详细信息
     */
    @PreAuthorize("@ss.hasPermi('event:event:query')")
    @GetMapping(value = "/{tdguid}")
    public AjaxResult getInfo(@PathVariable("tdguid") String tdguid)
    {
        return AjaxResult.success(dbEventService.selectDbEventByTdguid(tdguid));
    }

    /**
     * 新增event
     */
    @PreAuthorize("@ss.hasPermi('event:event:add')")
    @Log(title = "event", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbEvent dbEvent)
    {
        return toAjax(dbEventService.insertDbEvent(dbEvent));
    }

    /**
     * 修改event
     */
    @PreAuthorize("@ss.hasPermi('event:event:edit')")
    @Log(title = "event", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbEvent dbEvent)
    {
        return toAjax(dbEventService.updateDbEvent(dbEvent));
    }

    /**
     * 删除event
     */
    @PreAuthorize("@ss.hasPermi('event:event:remove')")
    @Log(title = "event", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(dbEventService.deleteDbEventByTdguid(id));
    }
}
